package com.example.a22310.myapplication.ViewModel.Post;


import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.example.a22310.myapplication.Beans.user;
import com.example.a22310.myapplication.Listener.PostListener;
import com.example.a22310.myapplication.Model.PostModel;
import com.example.a22310.myapplication.databinding.ActivityAddPostBinding;

import okhttp3.MultipartBody;

public class AddPostViewModel implements PostListener<user> {
    private ActivityAddPostBinding binding;
    private AppCompatActivity activity;
    private int userid;
    private MultipartBody.Part file;



    public AddPostViewModel(AppCompatActivity activity, ActivityAddPostBinding binding,int userid,
                            MultipartBody.Part file){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        this.file = file;
        binding.setAddpost(this);
    }


    public void upload(View view) {  //上传图片
        PostModel postModel=new PostModel();
        postModel.addPost(AddPostViewModel.this,userid,binding.editContent.getText().toString(),file);
    }

    public void back(View view) {  //上传图片
        activity.finish();
    }

    @Override
    public void onSuccess(user user) {

        Toast.makeText(activity,"上传成功",Toast.LENGTH_LONG).show();


    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败",Toast.LENGTH_LONG).show();
    }
}